﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Super.Hmi.Converters
{
    public class CollectionNullOrEmptyConverter : IValueConverter, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler? PropertyChanged;

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is INotifyCollectionChanged observable)
            {
                observable.CollectionChanged += (s, e) =>
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Convert)));
            }
            return value == null || ((IEnumerable)value).Cast<object>().Count() == 0;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            => throw new NotSupportedException();
    }
}
